/*
 * 文件名：DataDictionaryServiceImpl.java	 
 * 时     间：上午10:36:12
 * 作     者：Administrator       
 * 版     权： 2012-2022 湖南智软网络科技, 公司保留所有权利.
 * 联     系：http://www.073586.com/
 */
package com.local.service.impl;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.local.dao.mapersdic.DataDictionaryMapper;
import com.local.model.DataDictionary;
import com.local.model.DataDictionaryExample;
import com.local.model.DataTree;
import com.local.service.face.DataDictionaryService;
import com.qianhai.common.dao.face.BaseMapper;
import com.qianhai.common.service.impl.BaseServiceImpl;
import com.qianhai.common.utils.Tools;

/** 
 * 类描述:这里是类描述
 * @ClassName: DataDictionaryServiceImpl 
 * @author Administrator
 * @date 2016年8月18日 上午10:36:12 
 */
@Service
public class DataDictionaryServiceImpl  implements DataDictionaryService
{
	@Autowired
	private DataDictionaryMapper dataDictionaryMapper;
	@Override
	public List<DataDictionary> getValueByKey(String code)
	{
		// TODO Auto-generated method stub
	List<DataDictionary> dataDictionary=dataDictionaryMapper.getValueByKey(code);
		return dataDictionary;
	}


	@Override
	public void saveOrUpdateDataDictionary(DataDictionary dataDictionary)
	{
		dataDictionaryMapper.insert(dataDictionary);
		// TODO Auto-generated method stub
		
	}


	@Override
	public void updateByUuid(DataDictionary dataDictionary)
	{
		// TODO Auto-generated method stub
		dataDictionaryMapper.updateByPrimaryKey(dataDictionary);
	}


	@Override
	public void deleteByUuid(String uuid)
	{
		// TODO Auto-generated method stub
		dataDictionaryMapper.deleteByPrimaryKey(uuid);
	}


	@Override
	public DataDictionary selectByUuid(String uuid)
	{
		// TODO Auto-generated method stub
	DataDictionary dataDictionary=	dataDictionaryMapper.selectByPrimaryKey(uuid);
		return dataDictionary;
	}



	@Override
	public void insert(DataDictionary dataDictionary)
	{
		// TODO Auto-generated method stub
		dataDictionaryMapper.insert(dataDictionary);
	}


	@Override
	public List<DataDictionary> selectAll(DataDictionary dataDic_page)
	{
		// TODO Auto-generated method stub
	List<DataDictionary> dataDictionary=	dataDictionaryMapper.selectAll(dataDic_page);
		return dataDictionary;
	}


	@Override
	public List<String> getTree(List<String> list)
	{
		// TODO Auto-generated method stub
		return dataDictionaryMapper.getTree(list);
	}


	@Override
	public List<String> getTreeRoot(String attr1)
	{
		// TODO Auto-generated method stub
		return dataDictionaryMapper.getTreeRoot(attr1);
	}


	@Override
	public List<Map<Object, Object>> getAllTree()
	{
		// TODO Auto-generated method stub
		
		return dataDictionaryMapper.getAllTree();
	}


	@Override
	public Integer getCount()
	{
		// TODO Auto-generated method stub
		return dataDictionaryMapper.getCount();
	}


	@Override
	public void getPid(String attr1)
	{
		// TODO Auto-generated method stub
		DataDictionaryExample example1 = new DataDictionaryExample();
		example1.createCriteria().andAttr1EqualTo(attr1);
		List<DataDictionary> list = dataDictionaryMapper.selectByCondition(example1);
		remove(list);
		dataDictionaryMapper.deleteByPrimaryKey(attr1);

	}
	
	private void remove(List<DataDictionary> list){
		if(Tools.isEmpty(list)){
			return;
		}else{
			for (DataDictionary dic : list)
			{
				DataDictionaryExample example = new DataDictionaryExample();
				example.createCriteria().andAttr2EqualTo(dic.getAttr1());
				List<DataDictionary> dics = dataDictionaryMapper.selectByCondition(example);
				dataDictionaryMapper.deleteByCondition(example);
				remove(dics);
			}
		}
	}


	private List<DataTree> getChildrens(List<DataTree> trees, String pid) 
	{
		List<DataTree> son = new ArrayList<DataTree>();
		for(DataTree dt : trees)
		{
			if(pid.equals(dt.getpId()))
			{
				son.add(dt);
			}
		}
		return son;
	}
}
